<template>
<div id="loginApp">
  <a-form
      id="components-form-demo-normal-login"
      :form="form"
      class="login-form"
      @submit="handleSubmit"
  >
    <a-form-item>
      <a-input
          v-decorator="[
          'email',
          { rules: [{ required: true, message: 'Please input your username!' }] },
        ]"
          placeholder="邮箱"
      >
        <a-icon slot="prefix" type="user" style="color: rgba(0,0,0,.25)" />
      </a-input>
    </a-form-item>
    <a-form-item>
      <a-input
          v-decorator="[
          'password',
          { rules: [{ required: true, message: 'Please input your Password!' }] },
        ]"
          type="password"
          placeholder="密码"
      >
        <a-icon slot="prefix" type="lock" style="color: rgba(0,0,0,.25)" />
      </a-input>
    </a-form-item>
    <a-form-item>
      <a-checkbox
          v-decorator="[
          'remember',
          {
            valuePropName: 'checked',
            initialValue: true,
          },
        ]"
      >
        记住我
      </a-checkbox>
      <a class="login-form-forgot" href="">
        忘记密码？
      </a>
      <a-button type="primary" html-type="submit" class="login-form-button">
        登 录
      </a-button>
      <router-link :to="{name:'Register'}">立即注册</router-link>
    </a-form-item>
  </a-form>
</div>
</template>

<script>
import popUp from "@/utils/popUp";
export default {
  beforeCreate() {
    this.form = this.$form.createForm(this, { name: 'normal_login' });
  },
  methods: {
    handleSubmit(e) {
      e.preventDefault();
      this.form.validateFields((err, values) => {
        if (!err) {
          console.log('Received values of form: ', values);
          this.$axios({
            methods:"post",
            url:" https://mallapi.duyiedu.com//passport/login",
            data:{
              appkey:"zhoujiangyun_1618415564670",
              email:values.email,
              password:values.password,
            }
          }).then(resp=>{
            this.success("登录成功！");
            this.$router.push({name:"Total"});
          }).catch(err=>{
            this.error(err)
          })
        }
      });
    },
    ...popUp
  },
};
</script>
<style scoped lang="less">
#components-form-demo-normal-login .login-form {
  max-width: 300px;
}
#components-form-demo-normal-login .login-form-forgot {
  float: right;
}
#components-form-demo-normal-login .login-form-button {
  width: 100%;
}
#loginApp{
  width: 300px;
  margin: 0 auto;
  padding-top: 10%;
}


</style>